#!/bin/bash
case $1 in
    hibernate|suspend)
        pkill mythfrontend
        if [[ -f /etc/init/mythtv-backend.conf ]] ; then
            stop mythtv-backend
            stop mysql
        fi
        stop mythtv-monitor
    ;;
    thaw|resume)
        start mythtv-monitor
        if [[ -f /etc/init/mythtv-backend.conf ]] ; then
            if grep "^start on " /etc/init/mysql.conf ; then
                start mysql
            fi
            if grep "^start on " /etc/init/mythtv-backend.conf ; then
                start mythtv-backend
            fi
        fi
        if [[ -f /etc/init.d/transmission-daemon ]] ; then
            /etc/init.d/transmission-daemon restart
        fi
    ;;
esac
exit 0
